<template>
    <div class="resCommon">
        <div class="search">
            <div class="classify">
                <el-radio-group v-model="activeName" @change="toggle">
                    <el-radio-button label="public">公共</el-radio-button>
                    <el-radio-button label="tenant">私有</el-radio-button>
                    <el-radio-button label="share">共享</el-radio-button>
                </el-radio-group>
            </div>
            <div class="searchBox">
                <el-button class="addResBtn" :disabled="isPowerDisabled" type="primary" @click="addResBtn">新建资源</el-button>
                <search placeholder="请输入搜索内容" :live-search="true" :search-word.sync="searchName" @search="searchCon"/>
            </div>
        </div>
        <!-- 目录面包屑 -->
        <el-breadcrumb v-if="breadcrumbList.length>1" class="breadcrumb-wrap" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item 
                v-for="(item, index) in breadcrumbList"
                :key="item.id"
                @click.native="onClickBread(item, index)">
                <span class="cursor">{{item.name}}</span>
            </el-breadcrumb-item>
        </el-breadcrumb>
        <div v-else class="breadVisbility"> </div>
        <el-table :key='toggleIndex' v-loading="loading" :data="resourcePublic" stripe style="width: 100%">
            <el-table-column :label="tableHead[clickStep-1].first">
                <template slot-scope="scope">
                    <el-button v-if="clickStep==1" @click="menuDetail(scope.row)" type="text">{{scope.row.spaceName}}</el-button>
                    <el-button v-if="clickStep==2" @click="menuDetail(scope.row)" type="text">{{scope.row.tableName}}</el-button>
                    <span v-if="clickStep==3">{{scope.row.columnFamilyName}}</span>
                </template>
            </el-table-column>
            <el-table-column v-if="clickStep==1&&activeName=='public'" prop="powerList" label="包含权限">
                <template slot-scope="scope">
                    <span>{{scope.row.powerList}}</span>
                    <!-- <span v-for="(item,i) in scope.row.powerList.split(',')" :key=i> 
                        {{item}}
                        <span v-if="i!=scope.row.powerList.split(',').length-1"> , </span>
                    </span> -->
                </template>
            </el-table-column>
            <el-table-column v-if="clickStep!=1" label="分配的用户">
                <template slot-scope="scope">
                    <span v-for="(item,ind) in scope.row.userList" :key='ind'>
                        {{item}}
                        <span v-if="ind!=scope.row.userList.length-1">,</span>
                    </span>
                </template>
            </el-table-column>
            <el-table-column v-if="clickStep==2&&activeName=='share'" label="分享者">
                <template slot-scope="scope">
                    <span>{{scope.row.owner}}</span>
                </template>
            </el-table-column>
            <el-table-column v-if="clickStep!=1&&activeName=='tenant'" prop="tenantList" label="分享给的租户">
                <template slot-scope="scope">
                    <span v-for="(item,ind) in scope.row.tenantList" :key='ind'>
                        {{item}}
                        <span v-if="ind!=scope.row.tenantList.length-1">,</span>
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <span v-if="scope.row.powerList.length>1">
                        <!-- <el-tooltip content="详情" placement="top">
                            <el-button @click="resDetail(scope.row)" v-if="clickStep==1" type="text">
                                <i class="el-icon-view icon-fs"></i>
                            </el-button>
                        </el-tooltip> -->
                        <el-tooltip content="分配用户" placement="top">
                            <el-button v-if="clickStep!=1" type="text" @click="tenantBtn(scope.row)">
                                <i class="el-icon-files icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <el-tooltip content="分享" placement="top">
                            <el-button v-if="clickStep!=1&&activeName=='tenant'" type="text" @click="shareBtn(scope.row)">
                                <i class="el-icon-share icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <el-tooltip content="删除" placement="top">
                            <el-button v-if="activeName!='share'&&clickStep!='1'||activeName=='share'&&clickStep>'2'" type="text" @click="deleteBtn(scope.row)">
                                <i class="el-icon-delete icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                    </span>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页(默认 10条/页) -->
        <pagenation :pageInfo='pageinfo'></pagenation>
        <dialogCom :diaData='dialogData'></dialogCom>
    </div>
</template>

<script>
import DialogCom from '@/components/resource/TenantResource';
import Pagenation from '@/components/resource/Pagenation'
import resource from '@/mixins/resource'
import Search from '@/components/common/Search'
    export default {
        components:{DialogCom, Pagenation, Search},
        mixins:[resource],
        data() {
            return {
                pageinfo: {
                    tenantNum: 0,
                    currentPage: 1
                },
                dialogData:{
                    type: 'HBASE',
                    label:'命名空间',
                    addResourceTab: false,
                    titleTips: '',
                    opeBtn: '',
                    isDisabled: false,
                    operatorTips: '',
                    resOperate: false,
                    editData:{
                        url:''
                    }
                },
                activeName: 'public',
                tenantDetail: false,
                resourcePublic: [],
                formInline:{},
                newResRules: {
                    name: [
                        { required: true, message: '请输入活动名称', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ]
                },
                isPowerDisabled: true,
                path: this.$route.path.toLocaleUpperCase()
            }
        },
        mounted(){
            this.breadcrumbList = [
                {
                    name: '返回',
                    id: '0'
                }
            ],
            // 获取列表
            this.getResourceList();
        },
        methods:{
            toggle(tab){
                this.toggleIndex++;
                this.isPowerDisabled = true;
                this.activeName = tab;
                this.clickStep = 1;
                // 更新分页
                this.pageIndex = 1;
                this.currentPage = 1;
                this.breadcrumbList =  [
                    {
                        name: '返回',
                        id: '0'
                    }
                ]
                this.getResourceList();
            },
            addResBtn(){
                let parentId = this.breadcrumbList;
                this.dialogData.editData = {
                    clickStep: this.clickStep,
                    resourceId: parentId[parentId.length-1].id=='0'?this.privateId:parentId[parentId.length-1].id
                };
                if(this.activeName == 'tenant'){
                    this.dialogData.titleTips = '新建资源';
                    this.dialogData.resType = '2';
                } else if(this.activeName=='public'){
                    this.dialogData.titleTips = '新建公共资源';
                    this.dialogData.resType = '1';
                } else {
                    this.dialogData.titleTips = '新建资源';
                    this.dialogData.resType = '3';
                }
                this.dialogData.addResourceTab = true;
                this.dialogData.isDisabled = false;
            },
        }
    }
</script>

<style lang="scss" scoped>
    @import '~@/styles/resCommon.scss';
</style>